package com.example.myapplication.ui.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import com.alibaba.android.arouter.launcher.ARouter
import com.example.myapplication.databinding.FragmentSettingBinding
import com.example.myapplication.ui.AboutUsActivity
import com.lxj.xpopup.XPopup
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

class SettingFragment : Fragment() {

    private lateinit var binding: FragmentSettingBinding

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
    ): View {
        binding = FragmentSettingBinding.inflate(inflater, container, false)
        return binding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        binding.clPrivacyPolicy.setOnClickListener {
            //隐私政策
            ARouter.getInstance().build("/web/activity")
                .withString("url", "http://www.qiushudu.cn/privacy_policy.html").navigation()

        }
        binding.clUserAgreement.setOnClickListener {
            //用户协议
            ARouter.getInstance().build("/web/activity")
                .withString("url", "http://www.qiushudu.cn/license.html").navigation()

        }

        binding.clGy.setOnClickListener {
            //关于我们
            AboutUsActivity.start(requireContext())
        }

        binding.clUserBack.setOnClickListener {
            //用户反馈

            ARouter.getInstance().build("/feedback/activity").navigation()
        }

        binding.clGyapp.setOnClickListener {
            //关于app
            AboutUsActivity.start(requireContext())
        }

        binding.clUpdate.setOnClickListener {
            Toast.makeText(requireContext(), "正在检查更新...", Toast.LENGTH_SHORT).show()

            lifecycleScope.launch {
                delay(3000)
                Toast.makeText(requireContext(), "已经是最新版本了", Toast.LENGTH_SHORT).show()
            }
        }


    }

    companion object {
        fun newInstance(): SettingFragment {
            val args = Bundle()
            val fragment = SettingFragment()
            fragment.arguments = args
            return fragment
        }
    }
}